package com.wanghan.salary.config;

import lombok.Data;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;

/**
 * @author wanghan
 */
@Data
public class EmailConfig extends Properties {
    private String from;
    private String host;
    private Integer port;
    private String user;
    private String pass;

    public EmailConfig() {
        FileReader fr = null;
        try {
            File file = new File("");
            String path = file.getAbsolutePath();
            fr = new FileReader(path +"/application.properties");
            super.load(fr);
        } catch (Exception e) {
            System.out.println("配置文件解析失败，采用默认值");
            super.put("from", "309342006@qq.com");
            super.put("mail.smtp.host", "smtp.qq.com");
            super.put("mail.smtp.port", "465");
            super.put("mail.smtp.ssl", true);
            super.put("mail.smtp.auth", true);
            super.put("mail.smtp.user", "309342006@qq.com");
            super.put("mail.smtp.pass", "clhxovljhhgobigd");
            super.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        }
        this.from = super.getProperty("from", "309342006@qq.com");
        this.host = super.getProperty("mail.smtp.host", "smtp.qq.com");
        this.port = Integer.valueOf(super.getProperty("mail.smtp.port", "465"));
        this.user = super.getProperty("mail.smtp.user", "309342006@qq.com");
        this.pass = super.getProperty("mail.smtp.pass", "clhxovljhhgobigd");
//        super.list(System.out);
    }
}
